package com.dong.filter;

import com.dong.config.T012IocConfig;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * 用于 包扫描的自定义过滤规则
 * @see T012IocConfig
 */
public class MyTpyeFilter implements TypeFilter {
    /**
     *
     * @param metadataReader     可以读取到当前扫描类的信息
     * @param metadataReaderFactory     可以获取到任何其他类的信息
     * @return
     * @throws IOException
     */
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        //获取当前类注解信息
        AnnotationMetadata annotationMetadata =  metadataReader.getAnnotationMetadata();
        //获取当前扫描的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //获取当前资源信息
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println("---> "+className);
        if(className.contains("er")) {
            return true;
        }
        return false;
    }
}
